package com.jy.api.dao;

import com.jy.api.domain.CashCouponStatus;
import com.jy.api.domain.CashCouponTransaction;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;

/**
 * Created by xiaohua on 2019/1/18.
 */
public interface CashCouponTransactionDao extends CrudRepository<CashCouponTransaction, Integer> {


    Page<CashCouponTransaction> findByStoreIdAndStatusOrderByUseTimeDesc(String storeId, CashCouponStatus status, Pageable pageable);


    Page<CashCouponTransaction> findByStoreIdAndStatusOrderByGiveTimeDesc(String storeId, Pageable pageable);


    List<CashCouponTransaction> findByMemberIdAndStatusAndStoreIdAndEndTimeIsGreaterThanEqualOrderByGiveTimeDesc(String memberId, CashCouponStatus status, Date date, String storeId);

    @Query(value = "SELECT COUNT(`id`)  FROM `cash_coupon_transaction` WHERE `member_id` =?1 AND `status` =?2 AND `store_id` =?3", nativeQuery = true)
    BigInteger findByUse(String memberId, CashCouponStatus status, String storeId);


    List<CashCouponTransaction> findByMemberIdAndStatusAndStoreIdOrderByGiveTimeDesc(String memberId, CashCouponStatus status, String storeId);

    List<CashCouponTransaction> findByMemberIdAndStatusAndStoreIdAndEndTimeLessThanEqualOrderByGiveTimeDesc(String memberId, CashCouponStatus status, String storeId,Date date);

}
